package com.lzh.others.basejava.Thread_21.bilibili_course_thread.CompletableFuturePrac_07;

import com.lzh.others.basejava.Thread_21.utils.SmallTool;

import java.util.concurrent.TimeUnit;

/**
 * @author LiuZiHao
 * @date 创建时间:2023年05月22日 10:18:55
 */
public class Dish {
    /**
     * 菜名
     */
    private String name;

    /**
     * 制作时长(秒)
     */
    private Integer productionTime;

    public Dish() {
    }

    public Dish(String name, Integer productionTime) {
        this.name = name;
        this.productionTime = productionTime;
    }

    public void make() {
        SmallTool.sleepMillis(TimeUnit.SECONDS.toMillis(this.productionTime));
        SmallTool.printTimeAndThread(this.name + "制作完毕，来吃我吧");
    }

    public void makeUseCpu() {
        SmallTool.printTimeAndThread(this.name + "制作完毕，来吃我吧" + compute());
    }

    /**
     * 用来模拟 1s种的耗时操作
     */
    private static long compute() {
        long startTime = System.currentTimeMillis();
        long result = 0;
        for (int i = 0; i < Integer.MAX_VALUE / 4.5; i++) {
            result += i * i % 3;
        }
        return System.currentTimeMillis() - startTime;
    }

    public static void main(String[] args) {
        System.out.println(compute());
    }
}
